<template>
	<view class="index-content">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('Order')"
			barstyle="#45bc1b" Color="#fff"></TopBar>
		<view class="top-time" @click="pikershow=true">
			<u-icon name="calendar-fill"  color="#45bc1b" size="28"></u-icon>
			<text>{{formatTime(newTime)}}</text>
			<u-icon name="arrow-down" v-if="!pikershow" color="#45bc1b" size="24"></u-icon>
			<u-icon name="arrow-up" v-if="pikershow" color="#45bc1b" size="24"></u-icon>
		</view>
		<u-datetime-picker :show="pikershow" v-model="newTime" mode="date" dir="ltr" @close="pikershow=false"
			@cancel="pikershow=false" @confirm="selecettime" closeOnClickOverlay :cancelText="$t('TimeCancel')"
			:confirmText="$t('Confirm')">

		</u-datetime-picker>
		<view class="order-list">
			<scroll-view scroll-y="true" style="height:100%;width:100%" @scrolltolower="scrolldata">
				<!-- 我的订单 -->
				<u-empty v-if="myorderList.length==0 " style="padding-top: 200rpx;" mode="order"
					iconSize="100" textSize="14" :text="$t('OrderEmpty')">
				</u-empty>
				<view class="">
					<view class="list" :dir="i18nLocale=='ug'?'rtl':''" v-for="(item,index) in myorderList"
						@click="handdetail(item.id)">
						<view class="sub_title">

							<view class="" style="padding:0rpx 10rpx">
								<u-icon name="tags-fill" color="#45bc1b" size="28"></u-icon>
							</view>
							{{item.out_trade_no}}
						</view>
						<view class="time">
							<text>{{$t('TimePlaced')}}:</text>
							<text dir="ltr">{{item.paid_at}}</text>
							<u-icon name="shopping-cart-fill" color="#45bc1b" size="25" v-if="type=='new'"></u-icon>
							<u-icon name="bag-fill" color="#45bc1b" size="25" v-else-if="type=='stay_take'"></u-icon>
							<u-icon name="car-fill" color="#45bc1b" size="25" v-else-if="type=='in_send'"></u-icon>
							<u-icon name="checkmark-circle-fill" color="#45bc1b" size="25" v-else></u-icon>
						</view>
						<view class="address">
							<view class="steps">
								<!-- <view>{{$t('Take')}}</view><text></text> -->
								<view>{{$t('Give')}}</view>
							</view>
							<view class="">
								{{item.address.detail}}
							</view>

						</view>

						<view class="money">
							<!-- <view><text>{{$t('DeliveryFees')}}：</text>¥{{item.fee}}</view> -->
							<view><text>{{$t('TotalPrice')}}：</text>¥{{item.fee}}</view>
						</view>
						<view class="remarks">
							{{$t('Remark')}}：<text>{{item.remark}}</text>
						</view>
						<view class="remarks">
							{{$t('CustomerTime')}}：<view dir="ltr">{{item.arrived_at}}</view>
						</view>
						<view class="btns" v-if="type=='stay_take'">
							<!-- <view @click.stop="handphone(item.start_infor.start_mobile)">{{$t('ContactMerchant')}}
							</view> -->
							<view class="btn1" @click.stop="handshop(item.id)">{{$t('ConfirmArrival')}}</view>
						</view>
						<view class="btns" v-if="type=='in_send'">
							<view @click.stop="handphone(item.address.mobile)">{{$t('CallBuyer')}}</view>
							<view class="btn1" @click.stop="handservice(item.id)">{{$t('ConfirmDelivery')}}</view>
						</view>
						<view class="btn" style="background-color:#999999;" v-if="type=='end'">
							{{$t('Finish')}}
						</view>
					</view>
				</view>
				<Loading :show="tabloadshow" :text="$t('Loading')" style="width:100%;height:100%;position: absolute;">
				</Loading>
			</scroll-view>
		</view>
		<u-toast ref="uToast" :message="notmessage"></u-toast>
		<Loading :show="loadshow" bgColor="" iconName="circle" :text="$t('Loading')"></Loading>
	</view>
</template>

<script>
	import TopBar from "@/components/TopBar.vue"
	import HeaderTitle from "@/components/HeaderTitle.vue"
	import {
		getmyorder,
	} from '@/api/all.js';

	export default {
		components: {
			TopBar,
			HeaderTitle,
		},
		mounted() {

		},
		data() {
			return {
				acnav: 0,
				pikershow: false,
				newTime: this.formatTime(Number(new Date())),
				type: 'new',
				myorderList: [],
				notmessage: '请仔细填写!',
				pageSize: 5,
				page: 1,
				total: 0,
				to: 1,
				tabloadshow: false,
				loadshow: false,

			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
		},
		onLoad() {
			this.scrolldata()
		},
		methods: {
			selecettime(e) {
				this.newTime = this.formatTime(e.value);
				console.log(this.newTime, '+++++')
				this.pikershow = false;
				this.page = 1;
				this.total = 0;
				this.to = 1;
				this.myorderList=[];
				this.getmyOrder(4);
			},
			formatTime(timestamp) {
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = ('0' + (date.getMonth() + 1)).slice(-2);
				const day = ('0' + date.getDate()).slice(-2);
				const formattedDate = `${year}-${month}-${day}`;
				return formattedDate;
			},
			scrolldata() {
				if (this.to != this.total) {
					this.loadshow = true;
					this.getmyOrder(4)
				} else {

				}
			},
			handdetail(id) {
				uni.navigateTo({
					url: '/pages/index/orderdatail?id=' + id
				})

			},
			getmyOrder(status) {
				let that = this;
				getmyorder({
					status: status,
					date: that.newTime,
					per_page: that.pageSize,
					page: that.page,
				}).then((res) => {
					that.tabloadshow = false;
					console.log(res, '++++++')
					if (res.code == 200) {
						let data = res.body;
						that.total = data.total;
						that.to = data.to;
						that.page++;
						let mydata = that.myorderList.concat(data.data);
						that.myorderList = mydata;
						that.tabloadshow = false;
						that.loadshow = false;

					}
				})
			},
			handphone() {
				uni.makePhoneCall({
					phoneNumber: String(mobile)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index-content {
		width: 100%;
		height: 100%;
		box-sizing: border-box;

		.top-time {
			display: flex;
			align-items: center;
			justify-content: center;
			text {
				padding: 20rpx 30rpx;
			}

		}

		.topnav {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-around;
			background-color: $uni-bg-color-box;
			box-sizing: border-box;
			padding: 20rpx 20rpx;
			font-size: $uni-font-size-base;

			.acitem {
				color: $uni-color-topic;
			}
		}

		.order-list {
			width: 100%;
			height: calc(100% - 305rpx);
			box-sizing: border-box;
			padding: 0rpx 20rpx;

			.list {
				width: 100%;
				background: #FFFFFF;
				box-shadow: $uni-bg-shadow;
				border-radius: $uni-border-radius-lg;
				margin-top: 40rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 40rpx;
				box-sizing: border-box;

				.time {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.address {
					width: 100%;
					background: #FFFFFF;
					// border: 1rpx solid #E6E6E6;
					border-radius: 20rpx;
					display: flex;
					align-items: flex-start;
					flex-direction: row;
					justify-content: space-between;
					padding: 10rpx 20rpx;

					.steps {
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: space-between;

						view {
							width: 60rpx;
							height: 60rpx;
							background: $uni-color-topic;
							border-radius: 50%;
							background-color: $uni-color-topic;
							font-size: 20rpx;
							color: #F0F3F8;
							display: flex;
							align-items: center;
							justify-content: center;
						}

						view:last-child {
							background: #F3444B;
						}

						text {
							display: block;
							width: 1rpx;
							height: 60rpx;
							border: 1rpx dashed #F0F3F8;
						}
					}

					.name {
						width: 80%;
						height: 195rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.view {
							display: flex;
							width: 100%;
							flex-direction: column;
							height: 80rpx;

							view {
								width: 100%;
								font-size: 28rpx;
								color: #000;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}

							text {
								width: 100%;
								font-size: 26rpx;
								color: #808080;
								margin-top: 10rpx;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}
						}
					}

					.distance {
						height: 150rpx;
						display: flex;
						flex-direction: column;
						align-items: flex-end;
						justify-content: space-between;
						font-size: 28rpx;
						color: #000;

						.item {
							display: flex;
							flex-direction: column;
							align-items: center;
							justify-content: center;
							margin-bottom: 15rpx;
						}
					}

				}

				.sub_title {
					width: 100%;
					display: flex;
					align-items: center;
				}

				.money {
					width: 100%;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					view {
						font-size: 28rpx;
						color: #33AAFC;

						text {
							color: #000000;
						}
					}

					view:last-child {
						color: #E40E04;
					}
				}

				.remarks {
					width: 100%;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					font-size: 28rpx;
					color: #808080;

					text {
						color: #000000;
					}

					view {
						color: #33AAFC;
					}
				}

				.btn {
					width: 280rpx;
					height: 68rpx;
					background: $uni-color-topic;
					border-radius: 10rpx;
					margin: 20rpx 0;
					font-size: 28rpx;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.btns {
					width: 100%;
					padding: 20rpx 0;
					display: flex;
					align-items: center;
					justify-content: center;

					view {
						width: 100%;
						height: 68rpx;
						border: 1rpx solid $uni-color-topic;
						border-radius: 10rpx;
						margin: 0 10rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: $uni-color-topic;
						font-size: 28rpx;
					}

					.btn1 {
						color: #fff;
						background-color: $uni-color-topic;
					}
				}
			}
		}
	}
</style>